package com.mayikt;

/**
 * @Author: maplefire
 * @Description: priority优先级示例
 * @Date: 2022/06/16 18:31
 */
class PriorityThread implements Runnable {

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName() + "--i:" + i);
        }
    }
}

public class ThreadDemo06 {
    public static void main(String[] args) {
        PriorityThread priorityThread = new PriorityThread();
        Thread t1 = new Thread(priorityThread);
        Thread t2 = new Thread(priorityThread);
        // 设置了优先级，不代表每次都一定会被执行。只是CPU调度会优先分配
        t1.setPriority(10);
        t1.start();
        t2.start();
    }
}
